import Home from "@/pages/home";
import Login from "@/pages/login";
import Register from "@/pages/register";
import Search from "@/pages/search";
import detail from "@/pages/detail";
import AddCartSuccess from "@/pages/addCartSuccess";
import ShopCart from "@/pages/shopcart";
import Trade from "@/pages/trade";
import Pay from "@/pages/pay";
import PaySuccess from "@/pages/paySuccess";
import Center from "@/pages/center";
import Myorder from "@/pages/center/myorder";
import Teamorder from "@/pages/center/teamorder";
export default [
  {
    path: "/home",
    component: Home,
    meta: { show: true },
  },
  {
    path: "/login",
    component: Login,
    meta: { show: false },
  },
  {
    path: "/register",
    component: Register,
    meta: { show: false },
  },
  {
    name: "search",
    path: "/search/:keyword?",
    component: Search,
    meta: { show: true },
  },
  {
    path: "/",
    redirect: "/home",
  },

  {
    path: "/detail/:skuId",
    component: detail,
    meta: { show: true },
  },
  {
    path: "/addcartsuccess",
    component: AddCartSuccess,
    meta: { show: true },
  },
  {
    path: "/shopcart",
    component: ShopCart,
    meta: { show: true },
  },
  {
    path: "/trade",
    component: Trade,
    meta: { show: true },
    beforeEnter: (to, from, next) => {
      if (from.path == "/shopcart") {
        next();
      } else {
        //从哪来回哪去-->地址URL是正确的
        next(false);
      }
    },
  },
  {
    path: "/pay",
    component: Pay,
    meta: { show: true },
    //路由独享守卫
    beforeEnter: (to, from, next) => {
      if (from.path == "/trade") {
        next();
      } else {
        next(false);
      }
    },
  },
  {
    path: "/paysuccess",
    component: PaySuccess,
  },
  {
    path: "/center",
    component: Center,
    children: [
      {
        path: "myorder",
        component: Myorder,
      },
      {
        path: "teamorder",
        component: Teamorder,
      },
      {
        path: "/",
        redirect: "/center/myorder",
      },
    ],
  },
];
